package com.chinaunicom.gateway.props;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2021/3/31 21:39
 * Description:
 */

@Data
// 开启自动刷新
@RefreshScope
@ConfigurationProperties(prefix = "wo.cloud")
public class CloudApiProperties {

    // 监控中心和swagger的访问url
    private static final String[] ENDPOINTS = {
            "/oauth/**",
            "/actuator/**",
            "/v2/api-docs/**",
            "/swagger/api-docs",
            "/swagger-ui.html",
            "/doc.html",
            "/swagger-resources/**",
            "/webjars/**",
            "/druid/**",
            "/error/**",
            "/assets/**",
            "/auth/logout",
            "/auth/code",
            "/auth/sms-code"
    };

    // 是否开启 gateway 的开关(默认；不开启网关)
    private Boolean enable = false;

    private List<String> ignoreUrl = new ArrayList<>();


    // @PostConstruct该注解被用来修饰一个非静态的void（）方法。被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行，
    // 并且只会被服务器执行一次。PostConstruct在构造函数之后执行，init（）方法之前执行
    @PostConstruct
    public void iniIgnoreUrl() {
        // 将 ENDPOINTS 存放到 list集合中
        Collections.addAll(ignoreUrl, ENDPOINTS);
    }
}
